using Function.SkillEditor.Runtime;
using SCore.Function.Fixed;
using UnityEngine;

public class MainPlayer : MonoBehaviour, IClipRenderEnv
{
    private SkillRunLineLoader _skillRunLineLoader;
    private int _entityId;
    public Animator animator;
    public Animator _animator => animator;
    public GameObject go;
    public GameObject _go => go;

    public Transform GetBone(string bondName)
    {
        return this.transform.DeepFindChild(bondName);
    }

    private fp _battleTime;
    private double _renderTime;

    void Start()
    {
        SkillEntityData skillEntityData = new SkillEntityData()
        {
            _entityId = _entityId,
        };
        _skillRunLineLoader = new SkillRunLineLoader(skillEntityData);
        SkillRunRender.Instance.AddRender(_entityId, this);
    }

    private void Update()
    {
        float dt = Time.deltaTime;

        var lastRenderTime = _renderTime;
        _renderTime += dt;

        while (_renderTime > _battleTime.AsDouble())
        {
            _skillRunLineLoader.Tick(SkillRunMap.Instance.RunFrameRatio);
            _battleTime += SkillRunMap.Instance.RunFrameRatio;
        }

        var t = dt / (_battleTime.AsDouble() - lastRenderTime);
        SkillRunRender.Instance.Tick(dt);

        if (Input.GetKeyDown(KeyCode.A))
        {
            _skillRunLineLoader.AddSkillRunLines(1001);
        }
    }
}